<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>房间类型房内物品信息管理 iframe 框</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <style type="text/css">
        .mask {
            position: absolute;
            top: 0px;
            filter: alpha(opacity=60);
            background-color: white;
            z-index: 100000;
            left: 0px;
            opacity: 0.01;
            -moz-opacity: 0.01;
            display: none;
        }
    </style>
</head>
<body>
<div id="mask" class="mask"></div>
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"
     style="padding: 20px 30px 0 0;">
    <input type="hidden" id="Room_productId"/>
    <div class="layui-form-item">
        <label class="layui-form-label">房间类型</label>
        <div class="layui-input-inline">
            <select id="Room_typeRoom_product_typeId" lay-filter="Room_typeRoom_product_typeId">

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品名称</label>
        <div class="layui-input-inline">
            <select id="Product_Id" lay-filter="Product_Id">

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">赔偿金额(元)</label>
        <div class="layui-input-inline">
            <input type="text" id="price" lay-verify="required" placeholder="请填写金额" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="employee-submit" id="employee-submit"
               value="确认添加">
        <input type="button" lay-submit lay-filter="employee-edit" id="employee-edit"
               value="确认编辑">
    </div>
</div>

<script src="../../layuiadmin/layui/layui.js"></script>
<script src="../../js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
    //显示遮罩层
    function showMask() {
        $("#mask").css("height", $(document).height());
        $("#mask").css("width", $(document).width());
        $("#mask").show();
    }

    //隐藏遮罩层
    function hideMask() {
        $("#mask").hide();
    }
</script>
<script>
    //下拉框初始化
    $.ajax({
        url: '/roomProduct/toAdd',
        type: 'post',
        dataType: 'json',
        data: {},
        async: false,//设置阻断
        success: function (data) {
            //将下拉框中添加数据
            var modelList = data.room_product_type;
            if (modelList && modelList.length != 0) {
                for (var i = 0; i < modelList.length; i++) {
                    var option = "<option value=\"" + modelList[i].id + "\"";
                    option += ">" + modelList[i].name + "</option>";  //动态添加数据
                    $('#Room_typeRoom_product_typeId').append(option);
                }
            }
            var modelList1 = data.Product;
            if (modelList1 && modelList1.length != 0) {
                for (var i = 0; i < modelList1.length; i++) {
                    var option = "<option value=\"" + modelList1[i].id + "\"";
                    option += ">" + modelList1[i].name + "</option>";  //动态添加数据
                    $('#Product_Id').append(option);
                }
            }
        }
    });

    //根据父级页面判断，如果是修改，则添加默认值
    if (parent.Room_productType == "toUpdate") {
        $.ajax({
            url: parent.toUpdateURL,
            type: 'post',
            dataType: 'json',
            async: false,//设置阻断
            data: {"id": parent.Room_productId},
            success: function (data) {
                $("#Room_productId").val(parent.Room_productId),
                    //重新渲染表单元素

                    $("#price").val(data.data.price),
                    //选中下拉框中的option

                    $("#Room_typeRoom_product_typeId").find("option[value=" + data.data.room_product_type_id + "]").prop("selected", true),
                    $("#Product_Id").find("option[value=" + data.data.product_id + "]").prop("selected", true);
            }
        });

    }
    //layui配置
    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function () {
        var $ = layui.$
            , form = layui.form;
        //监听提交
        form.on('submit(employee-submit)', function (data) {
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            //获取id，若无则改为0
            var id = $("#Room_productId").val();
            if (id == null || id == "") id = 0;
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.ajax({
                url: parent.Room_productURL,
                type: 'post',
                dataType: 'json',
                data: {
                    "id": id,
                    "room_product_type_id": $("#Room_typeRoom_product_typeId").val(),
                    "product_id": $("#Product_Id").val(),
                    "price": $("#price").val()
                },
                success: function (data) {
                    parent.layer.msg(data.msg, {icon: data.icon, zIndex: layer.zIndex + 100});
                }
            });
            parent.layui.table.reload('Room_productTable'); //重载表格
            parent.layer.close(index); //再执行关闭
        });
    })


</script>
</body>
</html>